"""
作者：赛琳伟
日期：2023年04月03日
描述：
"""
from group import *
from cmds import *
import numpy as np
from collections import Counter


def householder(n):
    n = np.array([n.x, n.y, n.z])
    H = np.eye(3) - np.outer(n,n)
    return H

def Cs_permut(c, n, o):
    Point.zero = 0.01
    permut = [0]*(len(c)+1)
    n = n.unit()
    sym_atoms = []
    for a in c:
        sym_atoms.append(a - 2 * n.dot(a-o) * n)
    for i in range(len(c)):
        for j in range(len(c)):
            if c[j] == sym_atoms[i]:
                permut[i+1] = j+1
                break
        else:
            print('error: not found.')
    return permut

def C5_permut(c, n, o):
    Point.zero = 0.01
    permut = [0]*(len(c)+1)
    n = n.unit()
    sym_atoms = []
    for a in c:
        sym_atoms.append(a.rotate(2*pi/5, n, o))
    for i in range(len(c)):
        for j in range(len(c)):
            if c[j] == sym_atoms[i]:
                permut[i+1] = j+1
                break
        else:
            print('error: not found.')
    return permut


def C60Ih_group():
    c = read('C60.car')
    e1 = Cs_permut(c, Point(-1.87666000,2.58299000,5.16600000), Point(-0.93833000,1.29149500,2.58300000))
    e2 = C5_permut(c, Point(0,5.96008,-2.98004), Point(0.731952,3.98748,1.84177))
    e3 = C5_permut(c, Point(-3.50352,4.82181,2.98004), Point(-1.01968,3.41835,4.82181))
    e1 = Element(e1)
    e2 = Element(e2)
    e3 = Element(e3)
    g = Group()
    g.add_element(e1)
    g.add_element(e2)
    g.add_element(e3)
    g.gen()
    return g

def show_cycle():
    g = C60_Ih()
    for e in g._elem:
        c = e.cycle()
        print(Counter([len(_) for _ in c]))
        #n_cyc = e.n_cycle()
        #cycle_count[n_cyc] += 1


def C60Ih轨道(替换,g):
    '''计算一个替换在C60-Ih群下的等价替换'''
    result = []
    for e in g._elem:
        result.append([])
        for pos in 替换:
            result[-1].append(e._permut[pos+1]-1)
    return result

if __name__ == '__main__':
    C60_Ih()
